package com.itfreer.gis.map.style;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itfreer.form.api.BaseRestService;
import com.itfreer.form.api.BaseService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import com.itfreer.gis.map.style.entity.MapStyleEntity;
import com.itfreer.utils.ResponseEntity;

/**
 * 定义我的样式Rest服务接口
 */
@RestController
@RequestMapping("/styles")
@Api("我的样式")
public class RestMapStyleService extends BaseRestService<MapStyleEntity> {

	@Autowired(required = false)
	private MapStyleService service;

	@Reference(lazy = true, check = false)
	private MapStyleService dubboService;

	@Override
	protected BaseService<MapStyleEntity> getService() {
		return getServiceEx();
	}

	protected MapStyleService getServiceEx() {
		if (service == null) {
            return dubboService;
        } else {
            return service;
        }
	}

	/**
	 * 获取方案
	 */
	@ApiOperation(value = "获取方案", notes = "根据样式ID、浏览器、终端获取样式对象")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "id", value = "方案ID", paramType = "path", dataType = "String", required = true) })
	@PostMapping(value = "style/{id:.+}", produces = "application/json")
	public Map<String, Object> style(@PathVariable("id") String id, @RequestBody StyleParas paras) {
		return getServiceEx().getStyle(id, paras);
	}

	/**
	 * 获取图层列表
	 */
	@ApiOperation(value = "获取方案", notes = "根据样式ID、浏览器、终端获取图层列表数据")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "id", value = "方案ID", paramType = "path", dataType = "String", required = true) })
	@PostMapping(value = "layers/{id:.+}", produces = "application/json")
	public ResponseEntity<MapStyle> layers(@PathVariable("id") String id, @RequestBody StyleParas paras) {
		return new ResponseEntity<MapStyle>(getServiceEx().getLayers(id, paras));
	}

	/**
	 * 获取mb转换后的方案 此方法特为android原生提供，暂不支持方案的适配
	 */
	@ApiOperation(value = "获取方案")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "id", value = "方案ID", paramType = "path", dataType = "String", required = true) })
	@GetMapping(value = "mbstyle/{id:.+}", produces = "application/json")
	public Map<String, Object> mbstyle(@PathVariable("id") String id) {
		return getServiceEx().mbstyle(id);
	}

	/**
	 * 获取android原生下的方案数据
	 */
	@ApiOperation(value = "获取数据")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "id", value = "方案ID", paramType = "path", dataType = "String", required = true) })
	@PostMapping(value = "datas/{id:.+}", produces = "application/json")
	public ResponseEntity<MapStyle> datas(@PathVariable("id") String id) {
		return new ResponseEntity<MapStyle>(getServiceEx().datas(id));
	}
	
	/**
	 * 获取mb转换后的方案 此方法特为android原生离线下载提供，暂不支持方案的适配
	 */
	@ApiOperation(value = "获取离线下载方案")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "id", value = "方案ID", paramType = "path", dataType = "String", required = true) })
	@GetMapping(value = "offlinestyle/{id:.+}", produces = "application/json")
	public Map<String, Object> offlinestyle(@PathVariable("id") String id) {
		return getServiceEx().offlineStyle(id);
	}
}
